package com.itheima.duotai3;

public class Test {
    public static void main(String[] args) {
        Animal a = new Dog();
        a.eat();
        a.drink();
        if(a instanceof  Dog){
            Dog  d= (Dog) a;
            d.watchhome();
        }


        a = new Cat();
        a.eat();
        a.drink();
        if(a instanceof  Dog) {
            Dog d2 = (Dog) a;
            d2.watchhome();
        }


    }

}

abstract class Animal {
    public void drink() {
        System.out.println("喝水");
    }

    public abstract void eat();
}

class Dog extends Animal {
    @Override
    public void eat() {
        System.out.println("狗吃狗粮");
    }
    public void watchhome(){
        System.out.println("狗看家");
    }
}

class Cat extends Animal {
    @Override
    public void eat() {
        System.out.println("猫吃老鼠");
    }
}